$(function() {
    $('.layui-plus').click(function() {
        layer_iframe('余额提现', 'edit');
    });
    window.page = 1;
    window.limit = 10;
    window.options = {
        id: 'data_table',
        elem: '.layui-table.data-table',
        url: location.pathname + location.search,
        where: {},
        page: {
            curr: 1
        },
        limits: [10, 25, 50, 100],
        done: function(res, curr, first) {
            if (!res.data && curr > 1) {
                window.options.page.curr = curr - 1;
                window.tableIns.reload(window.options);
            }
            window.options.page.curr = curr;
            window.page = curr;
            window.limit = res.limit;
        },
        cols: [
            [{
                field:'username',
                title: '区域代理',
                unresize: true,
                align: 'center',
                
            }, {
                field: 'type',
                title: '返利类型',
                unresize: true,
                align: 'center',
                templet:function(d){
                    switch(d.type){
                        case 1: return '发布需求';break;
                        case 2: return '购买广告位';break;
                        case 3: return '购买服务';break;
                        default:return '';
                    }
                }
            }, {
                field: 'price',
                title: '返利金额',
                unresize: true,
                align: 'center'
            }, {
                field: 'add_time',
                title: '时间',
                unresize: true,
                align: 'center'
            }, {
                title: '操作',
                unresize: true,
                align: 'center',
                toolbar: '#toolbar_normal'
            }]
        ],
    };
    window.tableIns = laytable.render(window.options);
    laytable.on('tool(data_table)', function(obj) {
        if (obj.event === 'edit') {
            switch(obj.data.type){
                case 1 : layer_iframe('返利详情', '/before/need_apply/index?id=' + obj.data.foreign_key); break;
                case 2 : layer_iframe('返利详情', '/before/ad_buy/index?id=' + obj.data.foreign_key); break;
                case 3 : layer_iframe('返利详情', '/before/service_buy/index?id=' + obj.data.foreign_key); break;
            }
            
        } 
    });
});
